<?php
include_once('includes/survey_meta.php');
require_once('functions.php');

function output_stepwise() {
	ob_start();
	$next_str = __('Next >>', 'wp-surveys');
	$previous_str = __('<< Previous', 'wp-surveys');
	$finish_str = __('Finish ->', 'wp-surveys');
	$no_answer_text = __('No answer given. All questions must be answered.', 'wp-surveys');

?>
<div style="display:none;">
<?php
	wp_register_script('wp-surveys-stepwise', SURVEYS_ABS_URL_PATH . '/js/wp-surveys-stepwise.js', array('jquery'));
	wp_print_scripts('wp-surveys-stepwise');	
?>
<script type="text/javascript">
jQuery(document).ready(function() {
	wp_surveys_navigation_data.next_label = '<?php echo $next_str;?>';
	wp_surveys_navigation_data.previous_label = '<?php echo $previous_str;?>'; 
	wp_surveys_navigation_data.finish_label = '<?php echo $finish_str;?>';
	wp_surveys_navigation_data.no_answer_text = '<?php echo $no_answer_text;?>';
});
	
var wp_surveys_step_navigation_HTML = new Array(
	'<div class="wp_survey_navigate_div">',
	'	<form action="" method="POST">',
	'		<table width="100%" border="0" cellspacing="0" cellpadding="0">',
	'			<tr>',
	'				<td class="wp_surveys_navigate_button_div wp_surveys_navigate_button_previous_div" align="right" width="50%"><input type="button" id="wp_surveys_navigate_previous" name="wp_surveys_navigate_previous" class="wp_surveys_navigate_button wp_surveys_navigate_previous" value="<?php echo $previous_str?>" onClick="wp_surveys_previous_step()"/></td>',
	'				<td class="wp_surveys_navigate_button_div wp_surveys_navigate_button_next_div" align="left" width="50%"><input type="button" id="wp_surveys_navigate_next" name="wp_surveys_navigate_next" class="wp_surveys_navigate_button wp_surveys_navigate_next" value="<?php echo $next_str?>" onClick="wp_surveys_next_step()"/></td>',
	'			</tr>',	
	'		</table>',
	'	</form>',
	'</div>'
);
</script>
</div>
<?php
	$output = ob_get_contents();
	ob_end_clean();
	return $output;
}

function output_default_css() {
	return '<style type="text/css">@import url("'.SURVEYS_ABS_URL_PATH.'/css/wp-surveys.css");</style>';
}

$wp_survey_output_config = array();
function wp_survey_db_get_template ($survey_id, &$tpl_source, &$smarty_obj) {

	// do database call here to fetch your template,
	// populating $tpl_source
	$tpl_source = stripcslashes(stripcslashes(get_survey_meta($survey_id, 'user_report')));

  // replace <post>id</post> strings with actual posts in $tpl_source.
	$post_re = '/<post[^>]*>(?<post_id>.*)<\/post>/';
	if ( preg_match_all($post_re, $tpl_source, $m) != 0 ) {
		foreach($m['post_id'] as $post_id){
			$post = get_post($post_id);
			$tpl_source = str_replace('<post>'.$post_id.'</post>', '<content>'.$post->post_content.'</content>', $tpl_source); 
		}
	}

  return true;
}

function wp_survey_db_get_timestamp($survey_id, &$tpl_timestamp, &$smarty_obj)
{
  $tpl_timestamp = '';
  return true;
}

function wp_survey_db_get_secure($tpl_name, &$smarty_obj)
{
    // assume all templates are secure
    return true;
}

function wp_survey_db_get_trusted($tpl_name, &$smarty_obj)
{
    // not used for templates
}

function wp_survey_output_report($survey_id, $response_id) {
	include_once('lib/Smarty/libs/Smarty.class.php');

	$smarty = new Smarty;
	
	$smarty->compile_dir = dirname(__FILE__).'/templates_c';
//	$smarty->use_sub_dirs = false;
	$smarty->compile_check = true;
	$smarty->clear_compiled_tpl('db:'.$survey_id); 
	$smarty->debugging = false;
	
	// register the resource name "db"
	$smarty->register_resource("db", array("wp_survey_db_get_template",
	                                       "wp_survey_db_get_timestamp",
	                                       "wp_survey_db_get_secure",
	                                       "wp_survey_db_get_trusted"));
	
	wp_survey_assign_smarty_data($response_id, $smarty, $survey_id);

	ob_start();
	//exit (phpinfo());
//	echo $smarty->compile_dir;
	$smarty->display('db:'.$survey_id);
	$output = ob_get_contents();
	ob_end_clean();
	return $output;
}

/*function wp_survey_dompdf_create($content, $filepath){

	$dompdf = new DOMPDF();
	$dompdf->load_html($content);
	$dompdf->set_paper('letter', 'portrait');
	$dompdf->render();
	
	$tmpFile = fopen($filepath, 'w');
	fwrite($tmpFile, $dompdf->output());
	fclose($tmpFile);
}*/

function wp_survey_html2fpdf_create($content, $filepath){
	include_once("lib/html2fpdf/html2fpdf.php"); 

	$pdf = new HTML2FPDF('P', 'mm', 'Letter'); 

	$pdf->AddPage(); 
	$pdf->WriteHTML($content); 

	$pdf->Output($filepath, 'F'); 
	
}

include_once('lib/tcpdf/tcpdf.php');
include_once('lib/FPDI/fpdi.php');

class concat_pdf extends FPDI {

	var $files = array();
	var $total_pagecount = 0;
		
	public function Footer() {
		
	}
	
	public function Header() {
		
	}

	public function setFiles($files) {
		$this->files = array();
		for ($i = 0; $i<count($files); $i++) {
			array_push($this->files, $files['position_'.$i]);
		}
	}

	public function parseValue($replacements, $value) {
		foreach ($replacements as $key=>$replacement) {
			$value = str_replace('['.$key.']', $replacement, $value);
		}
		return $value;
	}

	public function pageWrite($pagenumber) {
		global $wp_survey_output_config;
		$pagecount = 0;
		$replacements = array('pagetotal' => $this->total_pagecount, 'pagenumber' => $pagenumber); 
		if (is_array($wp_survey_output_config['pagewrites']['page'.$pagenumber])) {
			foreach($wp_survey_output_config['pagewrites']['page'.$pagenumber] as $item) {
				$this->SetFont(isset($item['font']) ? $item['font'] : 'arialunicid0'); 
				$this->SetFontSize(isset($item['fontsize']) ? $item['fontsize'] : '8'); 
				$color = split(',', (isset($item['color']) ? $item['color'] : '0,0,0'));
				$this->SetTextColor($color[0], $color[1], $color[2]); 
				$this->SetXY($item['x'], $item['y']); 
				$this->Write(0, $this->parseValue($replacements, $item['value']));
			}
		}
		
		if (is_array($wp_survey_output_config['pagewrites']['all'])) {
			foreach($wp_survey_output_config['pagewrites']['all'] as $item) {
				if (isset($item['except'])) {
					$except = split(',', $item['except']);
					if (in_array(''+$pagenumber, $except)) continue;
				}
				$this->SetFont(isset($item['font']) ? $item['font'] : 'arialunicid0'); 
				$this->SetFontSize(isset($item['fontsize']) ? $item['fontsize'] : '8'); 
				$color = split(',', (isset($item['color']) ? $item['color'] : '0,0,0'));
				$this->SetTextColor($color[0], $color[1], $color[2]); 
				$this->SetXY($item['x'], $item['y']); 
				$this->Write(0, $this->parseValue($replacements, $item['value'])); 
			}
		}
	}	

	function concat() {
		$pagenumber = 0; 
    foreach($this->files AS $file) {
      $this->total_pagecount += $this->setSourceFile($file);
    }
    foreach($this->files AS $file) {
      $pagecount = $this->setSourceFile($file);
      for ($i = 1; $i <= $pagecount; $i++) {
    		$pagenumber++;
				$tplidx = $this->ImportPage($i);
				$s = $this->getTemplatesize($tplidx);
				$this->AddPage('P', array($s['w'], $s['h']));
				$this->useTemplate($tplidx);
				$this->pageWrite($pagenumber);
      }
    }
	}

}

function wp_survey_output_pdf($content) {
	global $wp_survey_output_config;
	$tmpFilePath = str_replace("\\", "/", dirname(__FILE__)).'/tmp';

	if (!file_exists($tmpFilePath)) {
		mkdir($tmpFilePath, 0755, true);
	}
	$unique = md5(uniqid(rand(), true));

	mkdir($tmpFilePath.'/'.$unique, 0755, true);

	$filepart = $tmpFilePath.'/'.$unique.'/Part';
	$filepath = $tmpFilePath.'/'.$unique.'/Report.pdf';
	
	//wp_survey_dompdf_create($content, $filepath);

	$partlist = array();
	foreach (grab_tags('part', $content) as $part) {
		$part_content = grab_tag('content', $part);
		$part_order = grab_tag('order', $part);
		$partlist['position_'.$part_order] = $filepart.$part_order.'.pdf';
		wp_survey_html2fpdf_create($part_content, $partlist['position_'.$part_order]);
	}
//	wp_survey_html2fpdf_create($content, $filepath);

	$filelist = array_merge(array(), $partlist);
	
	foreach ($wp_survey_output_config['pdfs']['pdf'] as $pdf) {
		$filelist['position_'.$pdf['order']] = $pdf['file'];
	}

//	$filelist = array($);

	$pdf =& new concat_pdf();
	
	$pdf->setFiles($filelist);
	$pdf->concat();

	$pdf->Output($filepath, 'F');

	foreach($partlist as $partfile) {
		//unlink($partfile);
	}

	return $filepath;
}

function wp_survey_output_pdf_preview() {
	global $wp_survey_output_config;
	if (isset($_POST['previewPDF'])) {
		$survey_id = $_POST['survey_id'];
		$response_id = isset($_POST['response_id']) ? $_POST['response_id'] : '0';
		ob_end_clean();
		
		header ("Content-type: application/pdf");

		$content = wp_survey_output_report($survey_id, $response_id);

		$wp_survey_output_config = grab_tag('config', $content, false);
		$wp_survey_output_config = xml2array($wp_survey_output_config);
		$wp_survey_output_config = $wp_survey_output_config['config'];

		$content = grab_tag('parts', $content);
		
//		try {
		$filename = wp_survey_output_pdf($content);

//		} catch (Exception $e) {
//			print_r($e);
//			echo '\n';
//			echo $content;
//		}
		
		
		$file = fopen($filename, 'r');
		
		echo fread($file, filesize($filename));
		
		fclose($file);
		
		//unlink($filename);
		//rmdir(str_replace('/Report.pdf', '', $filename));
		exit;
	}
}

function output_survey($survey_id) {
	global $wpdb, $current_user, $wp_surveys_tables, $blog_id, $wp_survey_output_config;
	
	ob_start();

	$open = $wpdb->get_var("SELECT `survey_open` FROM `".$wp_surveys_tables['survey']."` WHERE `survey_id`=".$survey_id." LIMIT 1;");
	$no_repost = get_survey_meta($survey_id, 'no_repost') == 'true';
	$has_posted = $wpdb->get_var("SELECT count(`response_id`) FROM `".$wp_surveys_tables['response']."` WHERE `survey_id`=".$survey_id." LIMIT 1;");

	if(!$open) {
?>
		<div class="wp_survey_closed"><?php echo __('Sorry, this survey is no longer open.', 'wp-surveys');?></div>
<?php
		return;	
	}

	
	if($_POST['wpsurveys_button'] == __('Submit Survey', 'wp-surveys') && $_SESSION['voted']) {
		wp_register_script('trimpath-template', SURVEYS_ABS_URL_PATH . '/js/trimpath-template.js');
		wp_print_scripts('trimpath-template');
?>
		<div class="wp_survey_completed"><?php echo __('Thank you for completing our survey!', 'wp-surveys');?></div>
<?php
		$user_report_type = get_survey_meta($survey_id, 'user_report_type');
		$user_report = get_survey_meta($survey_id, 'user_report');
		
		if ($user_report && $user_report != '' && $user_report_type != 'none') {
			$output = wp_survey_output_report($survey_id, $_SESSION['response_id']);


			if ($user_report_type == 'html' || $user_report_type == 'both') {
?>
		<div class="wp_survey_report"><?php echo $output;?></div>
<?php
			}
	
			if ($user_report_type == 'email' || $user_report_type == 'both') {
				require_once('lib/libmail/libmail.php');	
				$user_sql = 
					"SELECT distinct".
					"	u.user_email ".
					
					"FROM ".
					"	".$wp_surveys_tables['response']." r ".
					"	INNER JOIN ".$wp_surveys_tables['user']." u ON u.ID = r.user_id ".
					
					"WHERE ".
					"	r.response_id=".$_SESSION['response_id'];
				$user_email = $wpdb->get_var($user_sql);
//				$user_email = 'nielowait@gmail.com';
				$survey_sql = 
					"SELECT distinct".
					"	s.survey_name ".
					
					"FROM ".
					"	".$wp_surveys_tables['survey']." s ".
					"	INNER JOIN ".$wp_surveys_tables['response']." r ON r.survey_id = s.survey_id ".
		
					"WHERE ".
					"	r.response_id=".$_SESSION['response_id'];
						
				$survey_name = $wpdb->get_var($survey_sql);

				$admin_email = get_option( "admin_email" );

				if (function_exists('get_blog_option')) {
					$from_name = get_blog_option($blog_id, "blogname" ) == '' ? 'WordPress' : wp_specialchars( get_blog_option($blog_id,  "blogname" ) );
				} else {
					$from_name = get_option( "site_name" ) == '' ? 'WordPress' : wp_specialchars( get_option( "site_name" ) );
				}

		    $mail = new Mail();
			
				$from = "\"{$from_name}\" <{$admin_email}>";
				$subject = '[' . $from_name . '] ' . __('Survey Report.', 'wp-surveys');
				$message = "Thank you for completing the {$survey_name} survey

The attached file(s) contains your results.";
				
		    /**
		    * Set the from address of the email
		    */
		    $mail->From($from);
				
		    /**
		    * Set the to address of the email
		    */
		    $mail->To($user_email);

		    /**
		    * Set the subject of the email
		    */
		    $mail->Subject($subject);
		    
		    /**
		    * Set the text of the Email
		    */
//				$text_message = strip_tags(str_replace(array('<br>', '<br/>', '<br />', '<p>', '<p/>', '</p>', '<p />'), array('\n', '\n', '\n', '\n\n', '\n\n', '', '\n\n'), $message.'\n'.$output));
		    $mail->Body($message);

		    /**
		    * Set high priority for the email. This can also be:
		    * high/normal/low/1/3/5
		    */
		    $mail->Priority(3);

				$tmpFilePath = wp_survey_output_pdf($output);

		    $mail->Attach($tmpFilePath, 'application/octet-stream', 'attachment');

				try {
					foreach ($wp_survey_output_config['attachments']['attachment'] as $attachment) {
					    $mail->Attach($attachment, 'application/octet-stream', 'attachment');
					}
				} catch (Exception $e) {
					//probably no attachments. lazy coding, I know.
				}		
		    /**
		    * Set the HTML of the email. Any embedded images will be automatically found as long as you have added them
		    * using addEmbeddedImage() as below.
		    */
		    //$mail->setHTML($message);
				
				try {
//					$ret_val = $mail->send(array($user_email, 'nielowait@gmail.com'));
					$mail->Send();
				} catch (Exception $e) {
					echo 'Failed to send mail.<br/>'.$e->getMessage();
				}
				
				unlink($tmpFilePath);
				rmdir(str_replace('/Report.pdf', '', $tmpFilePath));
			}
		}
		$_SESSION['response_id'] = null;
		$_SESSION['voted'] = false;
	}
	
	if ($has_posted && $no_repost) {
?>
		<div class="wp_survey_no_repost"><?php echo __('This survey may only be completed once.', 'wp-surveys');?></div>
<?php 
		return;
	}	
	
	if ($has_posted && !$no_repost && $_POST['wpsurveys_button'] != __('Submit Survey', 'wp-surveys')) {
?>
		<div class="wp_survey_has_posted"><?php echo __('This survey has already been completed.', 'wp-surveys');?></div>
<?php 
	}	
	
	if ($_SESSION['novote'] == true) {
?>
		<div class="wp_survey_no_vote"><?php echo __('All answers must be completed.', 'wp-surveys');?></div>
<?php 
	}	
?>
		<div class="wp_survey_messages"></div>
<?php 
	
	if (!($has_posted && $no_repost) && $open) {
		$current_plugins = get_option('active_plugins');
		if ((file_exists(ABSPATH . PLUGINDIR . '/polyglot.php')) && (in_array('polyglot.php', $current_plugins)))
			$polyglot = true;
		$surveys = $wpdb->get_results("SELECT * FROM `".$wp_surveys_tables['survey']."` WHERE `survey_id`=".$survey_id." LIMIT 1;",ARRAY_A);
		if (sizeof($surveys)>0) foreach ($surveys as $survey) {
			$questions = $wpdb->get_results("SELECT * FROM `".$wp_surveys_tables['question']."` WHERE `survey_id`='".$survey['survey_id']."';",ARRAY_A);
?>
	<div class="wp_survey">
		<div class="wp_survey_info">
			<div class="wp_survey_name"><?php print(isset($polyglot)?stripcslashes(polyglot_filter($survey['survey_name'])):stripcslashes($survey['survey_name']));?></div>
			<div class="wp_survey_describe"><?php print(isset($polyglot)?stripcslashes(polyglot_filter($survey['survey_describe'])):stripcslashes($survey['survey_describe']));?></div>
		</div>
	
		<br />

<?php
			if($questions) {
?>
		<form id="wp_survey_form" action="http://<?php echo $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];?>" method="post">
<?php
				$q = 1;
				if (sizeof($questions)>0) foreach($questions as $question) {
					$answers = $wpdb->get_results("SELECT * FROM `".$wp_surveys_tables['answer']."` WHERE `question_id`=".$question['question_id'].";",ARRAY_A);
					//unset($extra_options);
?>
			<div id="wp_survey_question_<?php echo $q;?>" class="wp_survey_question_info<?php echo $question['question_group'] != '' ? (' wp_survey_question_group_'.str_replace('-', '_', sanitize_title($question['question_group']))) : '';?>">
				<input type="hidden" id="wp_survey_question_<?php echo $q;?>_id" value="<?php echo $question['question_id'];?>"/>
				<div class="wp_survey_question"><span class="wp_survey_question_number"><?php echo $q;?>. </span><?php print($polyglot?stripcslashes(polyglot_filter($question['question_text'])):str_replace('&lt;', '<', str_replace('&gt;', '>', stripcslashes($question['question_text']))));?></div>
<?php
					// Define types of questions
					if($question['question_type']=="one-vert") {
						//$forever = $question['question_forever'];  
						//if($forever != '')
							//$extra_options = explode(",", $forever);
						$a = 1;
						if (sizeof($answers) > 0) foreach ($answers as $answer) {
?>
				<span class="wp_survey_answer wp_survey_answer_vertical <?php echo $answer['answer_css'];?>">
					<table cellspacing="0" cellpadding="0" border="0">
						<tr>
							<td class="wp_survey_answer_input_td" vAlign="top">
								<span class="wp_survey_answer_number"><?php echo $a;?>. </span><input type="radio" id="answer_<?php echo $answer['answer_id'];?>" class="answer_<?php echo $question['question_id'];?>" name="answer_<?php echo $question['question_id'];?>" value="<?php echo $answer['answer_id'];?>" <?php echo $_POST['answer_'.$question['question_id']] == $answer['answer_id'] ? ' checked="checked"' : '';?>/>
							</td>
							<td class="wp_survey_answer_label_td">
								<label for="answer_<?php echo $answer['answer_id'];?>"><?php print($polyglot?stripcslashes(polyglot_filter($answer['answer_text'])):stripcslashes($answer['answer_text']));?></label>
							</td>
						</tr>
					</table>
				</span>
<?php
							$a++;
						}
						/*if(isset($extra_options)) {
							foreach($extra_options as $option) {
								print("<input type='radio' ");
								print(" name=\"option[".$question['question_id']."][".$q."]\"value=\"".$option."\">&nbsp;");
								print(trim( stripcslashes ($option) )."\n");
							}
						}*/
?>
				<br />
<?php
	
					} elseif($question['question_type']=="one-hori") {
						//$forever=$question['question_forever'];  
						//if($forever != '')
							//$extra_options = explode(",", $forever);
?>
				<br />
<?php
						$a = 1;
						if (sizeof($answers) > 0) foreach ($answers as $answer) {
?>
				<span class="wp_survey_answer wp_survey_answer_horizontal <?php echo $answer['answer_css'];?>">
					<br />
					<span class="wp_survey_answer_number"><?php echo $a;?>. </span><input type="radio" name="answer_<?php echo $question['question_id'];?>" value="<?php echo $answer['answer_id'];?>" <?php echo $_POST['answer_'.$question['question_id']] == $answer['$answer_id'] ? ' checked="checked"' : '';?>/>
					&nbsp;
					<?php print($polyglot?stripcslashes(polyglot_filter($answer['answer_text'])):stripcslashes($answer['answer_text']));?>
					&nbsp;
					&nbsp;
					<br />
				</span>
<?php
							$a++;
						}
						/*if(isset($extra_options)) {
							foreach($extra_options as $option) {
								print("<input type='radio' ");
								print(" name=\"option[".$question['question_id']."][".$q."]\" value=\"".$option."\">&nbsp;");
								print(trim( stripcslashes ($option) )."&nbsp;&nbsp;\n");
							}
						}*/
?>
				<br />
<?php			
					} elseif($question['question_type']=="one-menu") {
						//$forever=$question['question_forever'];  
						//if($forever != '')
							//$extra_options = explode(",", $forever);
?>
				<br />
				<select class="wp_survey_answer wp_survey_answer_menu" name="answer_<?php echo $question['question_id'];?>" style="width:90%">
					<option value="<?php echo __('No response recorded', 'wp-surveys');?>">-- <?php echo __('Select an answer below', 'wp-surveys');?></option>
<?php				
						if (sizeof($answers) > 0) foreach ($answers as $answer) {
?>
					<option value="<?php echo $answer['answer_id'];?>" <?php echo $_POST['answer_'.$question['question_id']] == $answer['answer_id'] ? ' selected="selected">' : '';?>>
						<?php echo $polyglot ? stripcslashes(polyglot_filter($answer['answer_text'])) : stripcslashes($answer['answer_text']);?> 		
					</option>
<?php
						}
						/*if(isset($extra_options)) {
							foreach($extra_options as $option) {
								print("<option value=\"".trim($option)."\" ");
								print(" >");
								print("".trim( stripcslashes ($option) )."</option>\n");
							}
						}*/
?>
				</select>
				<br />
<?php
					}
					/*if($question['question_type']=="mul-vert") {
						$running = 0;
						//$forever = $question['question_forever'];
						//if($forever != '')
							//$extra_options = explode(",", $forever);
						for($q=0;$q<10;$q++) { 
							$option="question_option_".$q;
							if($question[$option]!='') {
								print("<input type='checkbox' ");
								print(" name=\"option[".$question['question_id']."][".$running."]\" value=\"".$question[$option]."\">&nbsp;");
								print(stripcslashes ( $question[$option] )."\n");  
								$running++;
								}
							}
						if(isset($extra_options)) {
							foreach($extra_options as $options) {
								$q++;
								print("<input type='checkbox' ");
								print(" name='option[".$question['question_id']."][".$running."]' value='".trim( $options )."'>&nbsp;");
								print(trim( stripcslashes ($options) )."\n");        
								$running++;
								}
							}
						}
					if($question['question_type']=="mul-hori") {
						$forever=$question['question_forever'];  
						$running=0;
						if($forever != "")
							$extra_options = explode(",", $forever);
						print("<p>\n");
						for($q=0;$q<10;$q++) { 
							$option="question_option_".$q;
							if($question[$option]!='') {
								print("<input type='checkbox' ");
								print(" name='option[".$question['question_id']."][".$running."]' value='".$question[$option]."'>&nbsp;");
								print(stripcslashes ( $question[$option] )."&nbsp;&nbsp;\n");   
								$running++;
								}
							}
						if(isset($extra_options)) {
							foreach($extra_options as $options) {
								print("<input type='checkbox' ");
								print(" name='option[".$question['question_id']."][".$running."]' value='".trim( $options )."'>&nbsp;");
								print(trim( stripcslashes ($options) )."&nbsp;&nbsp;\n");  
								$running++;
								}
							}
						print("\n\n");
						}
					elseif($question['question_type']=="open-onep") {
						print("<div class=\"wpsurveys_text\"><input name='option[".$question['question_id']."][0]' style=\"height:30px\" value='".$filled."'></div>\n");
						}
					elseif($question['question_type']=="open-more") {
						print("<div class=\"wpsurveys_text\"><input name='option[".$question['question_id']."][0]' style=\"height:100px\" value='".$filled."'></div>\n");
						}
					else if($question['question_type']=="open-essa") {
						print("<div class=\"wpsurveys_text\"><input name='option[".$question['question_id']."][0]' style=\"height:200px\" value='".$filled."'></div>\n");
						}
					elseif($question['question_type']=="open-date") {
						print("<div class=\"wpsurveys_text\"><input name='option[".$question['question_id']."][0]' style=\"height:300px\" value='".$filled."'></div>\n");
						}*/
					//else print("Undefined.");
?>
			</div>
<?php
					$q++;
				}
?>
			<input type="hidden" id="question_count" value="<?php echo ($q-1);?>" />
			<input type="hidden" name="survey_id" value="<?php echo $survey['survey_id'];?>" />
			<input type="hidden" name="wpsurveys_button" value="<?php echo __('Submit Survey', 'wp-surveys');?>"/>
			<div class="wp_survey_submit_div">
				<input type="submit" name="wpsurveys_submit_button" value="<?php echo __('Submit Survey', 'wp-surveys');?>" class="wp_survey_submit" />
			</div>
		</form>
<?php
			} else { 
?>
		<div class="wp_survey_no_questions"><?php echo __('This survey has no questions yet.', 'wp-surveys');?></div>
<?php 
			}
?>
	</div>
<?php
		}
	}
	$output = ob_get_contents();
	ob_end_clean();
	return $output;
}	
?>